'''
Author: caishuyang
Date: 2023-02-21 16:08:38
LastEditors: caishuyang
LastEditTime: 2023-03-06 10:00:55
Description: 数据可视化播放(3D部分还需优化)
'''

import matplotlib.pyplot as plt
import numpy as np
import math
import cv2
import torch

class Player3D():
    def __init__(self):
        self.flag=True
        pass

    def playvideo(self,data):
        plt.ion()
        fig = plt.figure("3D")
        while self.flag:
            xyz=data.get()
            x=float(xyz[0,0])
            y=float(xyz[0,1])
            z=0#float(xyz[0,2])
            ax1 = plt.axes(projection='3d')
            ax1.set_xlim(-1,10)
            ax1.set_ylim(-1,10)
            ax1.set_zlim(-1,3)
            ax1.scatter3D(x,y,z,s=100,linewidths=1)
            fig.canvas.draw_idle()
            fig.canvas.flush_events() 
            plt.clf() #清除内存
        plt.close()


class Player2D():
    def __init__(self):
        self.flag=True
        pass

    def playvideo(self,data):
        while self.flag:
            xyz=data.get()
            canvas = 255*np.ones((600, 600, 3), dtype=np.uint8)
            x0=float(xyz[0,0])
            y0=float(xyz[0,1])
            r=5
            x=int(50*x0+50)
            y=int(50*y0+50)
            cv2.circle(canvas, (int(x), int(y)), r, (255, 0, 0),15)
            cv2.imshow('2D', canvas)
            cv2.waitKey(10)

if __name__=="__main__":
    play=Player3D()
